<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
	<button>发送请求</button>
</body>
<script>
	const btn = document.querySelector("button");
	btn.onclick = function(){
		const xhr = new XMLHttpRequest();
		xhr.timeout = 2000;// 指定超时的时间，单位是毫秒
		xhr.open("get","/myJson");
		xhr.send();
		xhr.onload = function(){
			console.log(xhr.response);
		}
		xhr.ontimeout = function(){
			console.log("ontimeout:当请求超时后执行")
		}
	}
</script>
</html>